﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!-- 权限验证 -->
    <script type="text/javascript" src="static/WebApi.js"></script>
    <title>员工列表</title>
</head>
<body>
    <!--top 导航-->
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 员工管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>

    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="admin_add('添加员工', 'admin-add.html', '800', '600')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i>添加员工</a>
                <input type="text" name="name_search" id="name_search" placeholder="请输入员工名称查询" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="button" onclick="search_name()"><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </span>
            <span class="r">当前数据：<strong id="count">&nbsp;</strong> 条，共<strong id="pagecount"></strong>页</span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg">
                <thead>
                    <tr class="text-c">
                        <th width="40">ID</th>
                        <th width="150">员工姓名</th>
                        <th width="150">员工账号</th>
                        <th width="150">联系电话</th>
                        <th width="130">加入时间</th>
                        <th width="100">是否已启用</th>
                        <th width="100">操作</th>
                    </tr>
                </thead>
                <tbody id="mybody">
                    <!--<tr class="text-c">
                        <td><input type="checkbox" value="1" name=""></td>
                        <td>1</td>
                        <td>admin</td>
                        <td>13000000000</td>
                        <td>admin@mail.com</td>
                        <td>超级管理员</td>
                        <td>2014-6-11 11:11:42</td>
                        <td class="td-status">
                            <span class="label label-success radius">已启用</span>
                        </td>
                        <td class="td-manage">
                            <a title="停用" href="javascript:;" onclick="admin_stop(this, '10001')" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑', 'admin-add.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this, '1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    <tr class="text-c">
                        <td><input type="checkbox" value="2" name=""></td>
                        <td>2</td>
                        <td>zhangsan</td>
                        <td>13000000000</td>
                        <td>admin@mail.com</td>
                        <td>员工</td>
                        <td>2014-6-11 11:11:42</td>
                        <td class="td-status">
                        <span class="label label-success radius">已启用</span>
                        </td>
                        <td class="td-manage">
                            <a title="停用" href="javascript:;" onclick="admin_stop(this, '10001')" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑', 'addrolemanagment.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this, '1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>                    </tr>-->
                </tbody>
                <tfoot id="myfoot">

                </tfoot>
            </table>
        </div>
    </div>
    <!--模态框-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--扩展js脚本-->
    <script type="text/javascript" src="static/Common.js"></script>
    <script type="text/javascript">

        $(function () {
            Showdivisionmanagement("", 1, 10);//根据员工姓名获取员工信息
        });

        //根据员工姓名获取员工信息
        function Showdivisionmanagement(S_name, pageindex, pagesize) {
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Staff/Selectpage",
                data: { search: S_name, PageIndex: pageindex, PageSize: pagesize },
                success: function (data) {
                    $("#mybody").empty();
                    $("#myfoot").empty();
                    $("#count").text(data.TotalSize);
                    $("#pagecount").text(data.PageCount);
                    var html = Array("");
                    $(data.Result).each(function (i, item) {
                        html.push('<tr class="text-c">');
                        html.push('<td>' + (i + 1) + '</td>');
                        html.push('<td>' + item.T_Name + '</td>');
                        html.push('<td>' + item.T_Account + '</td>');
                        html.push('<td>' + item.T_Phone + '</td>');
                        html.push('<td>' + (new Date(item.T_Date)).Format("yyyy-MM-dd hh:mm:ss") + '</td>');
                        html.push('<td class="td-status">');
                        if (item.T_State == 1) {
                            html.push('<span class="label label-success radius">已启用</span>');
                        }
                        else {
                            html.push('<span class="label label-default radius">已禁用</span>');
                        }
                        html.push('</td>');
                        html.push('<td class="td-manage">');
                        if (item.T_IsSystem != 0) {
                            if (item.T_State == 1) {
                                html.push('<a title="停用" href="javascript:;" onclick="admin_stop(this, \'' + item.T_StaffID + '\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                            }
                            else {
                                html.push('<a title="启用" href="javascript:;" onclick="admin_start(this,\'' + item.T_StaffID + '\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                            }
                            html.push('<a title="编辑" href="javascript:;" onclick="admin_edit(\'员工编辑\', \'admin-update.html\', \'' + item.T_StaffID + '\', \'800\', \'500\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>');
                            html.push('<a title="删除" href="javascript:;" onclick="admin_del(this, \'' + item.T_StaffID + '\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>');
                        }
                        html.push('</td>');
                        html.push('</tr>');
                    });
                    $("#mybody").append(html.join(""));

                    var page = Array();
                    page.push('<tr><td style="text-align:right;" colspan="7">');
                    if (pageindex > 1 && data.PageCount > 0) {
                        page.push('<input  type="button"  class="btn btn-primary radius" onclick="Showdivisionmanagement(\'' + S_name + '\',' + (pageindex - 1) + ',' + pagesize + ')" value="上一页" />');
                    }
                    page.push('<lable style="font-size:16px" ">第' + pageindex + '页</label>');
                    if (pageindex < data.PageCount && data.PageCount > 0) {
                        page.push('<input type="button"  class="btn btn-primary radius" onclick="Showdivisionmanagement(\'' + S_name + '\',' + (pageindex + 1) + ',' + pagesize + ')" value="下一页" />');
                    }

                    page.push('</tr>');
                    var d1 = page.join("");
                    $("#myfoot").append(d1);

                }
            });

        };

        //查询功能
        function search_name() {
            var name = $("#name_search").val();
            Showdivisionmanagement(name, 1, 10);//根据员工姓名获取员工信息
        }

        /*
            参数解释：
            title	标题
            url		请求的url
            id		需要操作的数据id
            w		弹出层宽度（缺省调默认值）
            h		弹出层高度（缺省调默认值）
        */
        /*员工-增加*/
        function admin_add(title, url, w, h) {
            //parent.layer_show(title, url, w, h);
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }

        /*员工-删除*/
        function admin_del(obj, id) {
            parent.layer.confirm('确认要删除吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    type: "post",
                    url: ApiUrl + "api/Staff/Delete",
                    data: {
                        "": id
                    },
                    success: function (data) {
                        if (data == true) {
                            $(obj).parents("tr").remove();
                            parent.layer.msg('已删除!', { icon: 1, time: 1000 });

                        }
                        else {
                            parent.layer.msg('删除失败!', { icon: 2, time: 1000 });
                        }
                    }
                });

            });
        }

        /*员工-编辑*/
        function admin_edit(title, url, id, w, h) {
            var index = layer.open({
                type: 2,
                title: title,
                content: url + "?" + id
            });
            layer.full(index);
        }

        /*员工-停用*/
        function admin_stop(obj, id) {
            parent.layer.confirm('确认要停用吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    url: ApiUrl + 'api/Staff/UpdateState',
                    type: 'post',
                    data: { T_StaffID: id, T_State: 0 },
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg('已停用!', { icon: 5, time: 1000 });
                            window.location.reload();
                        }
                        else {
                            parent.layer.msg("停用失败！", { icon: 2, time: 1000 });
                        }
                    }
                });


            });
        }

        /*员工-启用*/
        function admin_start(obj, id) {
            parent.layer.confirm('确认要启用吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    url: ApiUrl + 'api/Staff/UpdateState',
                    type: 'post',
                    data: { T_StaffID: id, T_State: 1 },
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg('已启用!', { icon: 6, time: 1000 });
                            window.location.reload();
                        }
                        else {
                            parent.layer.msg("启用失败！", { icon: 2, time: 1000 });
                        }
                    }
                });

            });
        }
    </script>
</body>
</html>
